﻿using System;
using System.Configuration;

namespace MDCAdminTool.Configuration
{
	/// <summary>
	/// Config collection for <see cref="ClusterConfigElement"/>
	/// </summary>
	public class ClustersCollection : ConfigurationElementCollection
	{
		/// <summary>
		/// Stongly typed indexer for iteration
		/// </summary>
		/// <param name="index"></param>
		/// <returns></returns>
		public ClusterSettingElement this[Int32 index]
		{
			get
			{
				return BaseGet(index) as ClusterSettingElement;
			}
			set
			{
				if (BaseGet(index) != null)
				{
					BaseRemoveAt(index);
				}
				BaseAdd(index, value);
			}
		}

		protected override ConfigurationElement CreateNewElement()
		{
			return new ClusterSettingElement();
		}

		protected override Object GetElementKey(ConfigurationElement element)
		{
			return ((ClusterSettingElement)element).ConnectionString;
		}
	}
}